package com.ruoyi.personnel.salary.transfer.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.salary.transfer.domain.TransferDto;
import com.ruoyi.personnel.salary.transfer.domain.TransferCond;
import com.ruoyi.personnel.salary.transfer.domain.TransferDomain;
import com.ruoyi.personnel.salary.transfer.service.ITransferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 工资转账记录
 * 视图层
 */
@RestController
@RequestMapping("/salary/transfer")
@Api(value = "工资转账记录模块", tags = "工资转账记录接口")
public class TransferController extends BaseController {
    @Autowired
    private ITransferService transferService;

    /**
     * 获取工资转账记录列表
     * @param cond 搜索条件
     * @return
     */
    @ApiOperationSupport(includeParameters = {"TransferCond.staffId", "TransferCond.bankAccount", "TransferCond.createTime"})
    @ApiOperation(value = "获取工资转账记录列表",notes = "查询所有工资转账记录信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody TransferCond cond) {
        startPage();
        List<TransferDto> transferList = transferService.selectTransferList(cond);
        return getDataTable(transferList);
    }

    /**
     * 新增工资转账记录
     * @param transfer
     * @return
     */
    @ApiOperation(value = "新增工资转账记录", notes = "新增工资转账记录")
    @ApiImplicitParam(name = "transfer", value = "新增工资转账记录", dataType = "TransferDomain")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody TransferDomain transfer) {
        return toAjax(transferService.insertTransfer(transfer));
    }

    /**
     * 修改工资转账记录
     *
     * @param transfer
     * @return
     */
    @ApiOperation(value = "修改工资转账记录", notes = "修改工资转账记录")
    @ApiImplicitParam(name = "transfer", value = "修改工资转账记录(可修改参数：bankAccount、actualSalary、remark)", dataType = "TransferDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody TransferDomain transfer) {
        return toAjax(transferService.updateTransfer(transfer));
    }

    /**
     * 删除工资转账记录
     * 仅修改删除标志位
     *
     * @param transfer
     * @return
     */
    @ApiOperation(value = "删除工资转账记录", notes = "删除工资转账记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody TransferDomain transfer) {
        return toAjax(transferService.updateTransferDeleteFlag(transfer));
    }
}
